package com.xxr.lib_popup.ui;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.xxr.lib_popup.R;
import com.xxr.lib_popup.utlis.DialogBase;

/**
 * 作者：姜澜
 * 时间：2020/6/10
 * 简述：对话弹出框
 * 邮箱：31679104@qq.om
 */
public class Dialogue extends DialogBase.Builder {

    private TextView dialogueTitle,dialogueMessage;
    private Button dialogueOk,dialogueCancel;

    public Dialogue(Activity activity) {
        super(activity);
        //设置大小
        getView(0.9f,0);

    }

    public Dialogue(Context context) {
        super(context);
        getView(0.9f,0);
    }

    @Override
    protected void initBind() {
        dialogueTitle = findViewById(R.id.dialog_title);
        dialogueMessage = findViewById(R.id.dialog_message);

        dialogueOk = findViewById(R.id.dialog_ok);
        dialogueCancel = findViewById(R.id.dialog_cancel);
    }

    @Override
    protected void initView() {
        if ("".equals(title) || null==title){
            setTitle("提示");
        }

        dialogueTitle.setText(title);
        dialogueMessage.setText(message);

        //设置确定按钮
        dialogueOk.setText(positiveButtonText);
        if (null != positiveButtonClickListener){
            dialogueOk.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    positiveButtonClickListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                    dialog.dismiss();
                }
            });
        }else {
            dialogueOk.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });
        }

        //设置取消按钮
        if (!"".equals(negativeButtonText) && null != negativeButtonText){
            dialogueCancel.setText(negativeButtonText);
            if (null != negativeButtonClickListener){
                dialogueCancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        negativeButtonClickListener.onClick(dialog,DialogInterface.BUTTON_NEGATIVE);
                        dialog.dismiss();
                    }
                });
            }else {
                dialogueCancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });
            }
        }else {
            dialogueCancel.setVisibility(View.GONE);
        }

    }

    @Override
    protected int getLayout() {
        return R.layout.dialogue_layout;
    }

    @Override
    protected int getAnim() {
        return R.style.DialogueStyle;
    }
}
